package logic

import (
	"context"
	"gorm.io/gorm"
	"taobao-merchandis/taobaorpc/models/mysql"

	"taobao-merchandis/taobaorpc/internal/svc"
	"taobao-merchandis/taobaorpc/taobaorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShopUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShopUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopUpdateLogic {
	return &ShopUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShopUpdateLogic) ShopUpdate(in *taobaorpc.ShopUpdateRequest) (*taobaorpc.ShopUpdateResponse, error) {
	// todo: add your logic here and delete this line

	var shop mysql.Shop
	mysql.DB.Debug().Where("id=?", in.Id).Find(&shop)
	m := mysql.Shop{
		Model:   gorm.Model{ID: uint(in.Id)},
		Image:   in.Image,
		Name:    in.Name,
		Comment: in.Comment,
		Price:   float64(in.Price),
	}
	mysql.DB.Debug().Updates(&m)
	return &taobaorpc.ShopUpdateResponse{
		ShopId: int64(m.ID),
	}, nil
}
